package com.cet.designpatterns.memento;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-09-24 10:13
 **/
public class Client {
    public static void main(String[] args) {
        Caretaker caretaker = Caretaker.getInstance();
        System.out.println("=========游戏开始，人物初始化=========");
        Originator boss01 = new Originator();
        boss01.setName("孟获");
        boss01.setState("100HP");
        System.out.println(boss01);
        Originator challenger = new Originator();
        challenger.setName("张飞");
        challenger.setState("100HP");
        System.out.println(challenger);
        caretaker.setMemento(boss01.getName(), boss01.saveStateMemento());
        caretaker.setMemento(challenger.getName(),challenger.saveStateMemento());
        System.out.println("========" + challenger.getName() + "挑战" + boss01.getName() + "，战斗开始=========");
        boss01.setState("0HP");
        challenger.setState("30HP");
        System.out.println(boss01);
        System.out.println(challenger);
        System.out.println("========" + challenger.getName() + "战胜" + boss01.getName() + "=========");
        System.out.println("=========游戏人物状态重置==========");
        boss01.restoreState(caretaker.getMemento(boss01.getName()));
        challenger.restoreState(caretaker.getMemento(challenger.getName()));
        System.out.println(boss01);
        System.out.println(challenger);
    }
}
